import '../../service/Path.dart';
import '../dto/base/Resp.dart';
import '../dto/business/Message.dart';
import '../dto/business/PullData.dart';
import '../dto/business/SendData.dart';
import '../dto/business/WebRtcData.dart';
import 'RpcService.dart';

class RpcMessageService extends RpcService {
  Future<OkResp> sendMessage(MessageObject messageObject, [int? timeOutSecond = 60]) async {
    return sendDataAndOk(ImPath.imMessage, messageObject, OkResp.fromJson, timeOutSecond);
  }

  Future<OkListResp> sendMessages(List<MessageObject> messageObjects, [int? timeOutSecond = 60]) async {
    return sendDataAndOk(ImPath.imMessages, new MessageObjectsReq(messageObjects: messageObjects), OkListResp.fromJson, timeOutSecond);
  }

  Future<OkResp> sendReadMessages(MessageReadReq messageReadReq, [int? timeOutSecond = 60]) async {
    return sendDataAndOk(ImPath.readMessages, messageReadReq, OkResp.fromJson, timeOutSecond);
  }

  Future<OkResp> sendWithdrawMessages(MessageWithdrawReq messageWithdrawReq, [int? timeOutSecond = 60]) async {
    return sendDataAndOk(ImPath.withdrawMessages, messageWithdrawReq, OkResp.fromJson, timeOutSecond);
  }

  Future<OkResp> sendDeleteMessages(MessageDeleteReq messageDeleteReq, [int? timeOutSecond = 60]) async {
    return sendDataAndOk(ImPath.withdrawMessages, messageDeleteReq, OkResp.fromJson, timeOutSecond);
  }

  Future<OkResp> sendDataChange(DataChangeReq dataChangeReq, [int? timeOutSecond = 60]) async {
    return sendDataAndOk(ImPath.dataChange, dataChangeReq, OkResp.fromJson, timeOutSecond);
  }

  Future<OkResp> sendFileUploadSuccess(FileUploadSuccessReq fileUploadSuccessReq, [int? timeOutSecond = 60]) async {
    return sendDataAndOk(ImPath.fileUploadSuccess, fileUploadSuccessReq, OkResp.fromJson, timeOutSecond);
  }
}

class RpcGroupService extends RpcService {
  Future<OkResp> groupCreate(GroupCreateReq groupCreateReq) async {
    return this.sendDataAndOk(ImPath.groupCreate, groupCreateReq, OkResp.fromJson, 60);
  }

  Future<OkResp> groupAdd(GroupCreateReq groupCreateReq) async {
    return this.sendDataAndOk(ImPath.groupAdd, groupCreateReq, OkResp.fromJson, 60);
  }

  Future<GroupInfoItem> pullGroupInfo(GroupInfoReq groupInfoReq) async {
    return this.sendDataAndOk(ImPath.groupInfo, groupInfoReq, GroupInfoItem.fromJson, 60);
  }
}

class RpcBaseService extends RpcService {

  Future<OkListResp> createCollect(CollectCreateReq collectCreateReq) async {
    return this.sendDataAndOk(ImPath.collectCreate, collectCreateReq, OkListResp.fromJson, 60);
  }

  Future<OkResp>  deleteCollect(DelReq delReq) async {
    return this.sendDataAndOk(ImPath.collectDelete, delReq, OkResp.fromJson, 60);
  }
}

class RpcHeartService extends RpcService {

  Future<PongResp> pingToServer(PingReq pingReq) async {
    return this.sendDataAndOk(ImPath.pingToServer, pingReq, PongResp.fromJson, 60);
  }
}

class RpcWebRtcService extends RpcService {

  Future<InvitationResultList> sendWebRtcInvitation(WebRtcInvitationReq webRtcInvitationReq) async {
    return this.sendDataAndOk(ImPath.webRtcInvitation, webRtcInvitationReq, InvitationResultList.fromJson, 60);
  }

  Future<OkResp> sendWebRtcInvitationResult(WebRtcInvitationResultReq invitationResult) async {
    return this.sendDataAndOk(ImPath.webRtcInvitationResult, invitationResult, OkResp.fromJson, 60);
  }

  Future<OkResp> sendWebRtcCancel(WebRtcCancelReq cancelReq) async {
    return this.sendDataAndOk(ImPath.webRtcCancel, cancelReq, OkResp.fromJson, 60);
  }
}